var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[];}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	};
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0;}
			if(c.mh==c.offsetHeight){c.style.overflow='visible';}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1);},t);}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1);},t);}
	};
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible';}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px';
	}
	return{dd:dd};
}();

function formatarInteiro(campo, event) {
	campo.value = campo.value.replace(/\D+/, '');
}

function formatarTelefone(campo, event)
{
   var rExp = /[^\0-\9]|\-|\.|\//g;
   var vr = campo.value.replace(rExp, "");

 	vr = vr.replace( "/", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );

	var saida = vr.substring(0, 4);
	if (campo.value.length >= 4)
		saida += "-" + vr.substring(4, 8);

    campo.value = saida;
}

function formatarData(campo, event)
{
   var rExp = /[^\0-\9]|\-|\.|\//g;
   var vr = campo.value.replace(rExp, "");

 	vr = vr.replace( "/", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );

	var saida = vr.substring(0, 2);
	if (campo.value.length >= 2)
		saida += "/" + vr.substring(2, 4);
	if (campo.value.length >= 5)
		saida += "/" + vr.substring(4, 8);

    campo.value = saida;
}

function formatarCPF(campo, event)
{
   var rExp = /[^\0-\9]|\-|\.|\//g;
   var vr = campo.value.replace(rExp, "");

 	vr = vr.replace( "/", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );

	var saida = vr.substring(0, 3);
	if (campo.value.length >= 3)
		saida += "." + vr.substring(3, 6);
	if (campo.value.length >= 7)
		saida +=  "." + vr.substring(6, 9);
	if (campo.value.length >= 11)
		saida +=  "-" + vr.substring(9, 11);

    campo.value = saida;
}

function formatarCEP(campo, event)
{
   var rExp = /[^\0-\9]|\-|\.|\//g;
   var vr = campo.value.replace(rExp, "");

 	vr = vr.replace( "/", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );

	var saida = vr.substring(0, 2);
	if (campo.value.length >= 2)
		saida += "." + vr.substring(2, 5);
	if (campo.value.length >= 6)
		saida +=  "-" + vr.substring(5, 8);

    campo.value = saida;
}

function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


	if(document.all) { // Internet Explorer
	    nTecla = evtKeyPress.keyCode;
	} else if(document.layers) { // Nestcape
	    nTecla = evtKeyPress.which;
	} else {
	    nTecla = evtKeyPress.which;
	    if (nTecla == 8) {
	        return true;
	    }
	}

    sValue = objeto.value;

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"));
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "));

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    objeto.value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas números...
        return ((nTecla > 47) && (nTecla < 58)); } 
      else { // qualquer caracter...
        return true;
      } 
    }
    else {
      return true;
    }
  }

function loginRequired(){
	  document.getElementById('menu:loginRequired').click();  
}

function formatarValor(campo, separador_milhar, separador_decimal, tecla) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? tecla.which : tecla.keyCode;

	if (whichCode == 13) return true; // Tecla Enter
	if (whichCode == 8) return true; // Tecla Delete
	key = String.fromCharCode(whichCode); // Pegando o valor digitado
	if (strCheck.indexOf(key) == -1) return false; // Valor inválido (não inteiro)
	len = campo.value.length;
	for(i = 0; i < len; i++)
	if ((campo.value.charAt(i) != '0') && (campo.value.charAt(i) != separador_decimal)) break;
	aux = '';
	for(; i < len; i++)
	if (strCheck.indexOf(campo.value.charAt(i))!=-1) aux += campo.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) campo.value = '';
	if (len == 1) campo.value = '0'+ separador_decimal + '0' + aux;
	if (len == 2) campo.value = '0'+ separador_decimal + aux;

	if (len > 2) {
		aux2 = '';

		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += separador_milhar;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}

		campo.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		campo.value += aux2.charAt(i);
		campo.value += separador_decimal + aux.substr(len - 2, len);
	}

	return false;
}